package client;

import java.util.Map;
import java.util.Set;

import org.apache.log4j.Logger;

import com.cps.platform.core.Mapbean;
import com.cps.platform.client.config.ConfigClient;

/**
 * <p>
 * 文件名称: ConfigClientMain.java
 * </p>
 * <p>
 * 文件描述: 配置测试MAIN
 * <p>
 * 版权所有: 版权所有(C)2011
 * </p>
 * <p>
 * 公 司: 联通系统集成有限公司
 * </p>
 * <p>
 * 完成日期：2012-12-10
 * </p>
 * 
 * @author ChenZhang
 */
public class ConfigClientMain {

	private static Logger log = Logger.getLogger(ConfigClientMain.class);
	
	public static void main(String[] args) {
		String appId = "appId";
		String authToken = "authToken";
		
		ConfigClientMain m = new ConfigClientMain();
		ConfigClient client = new ConfigClient();
		
		Mapbean mapBean = null;
		
		log.info("addConfig----------------------------");
		String key = "testKey01";
		String value = "key20121210001";
		client.addConfig(appId, authToken, key, value);
		mapBean = client.getConfig(appId, authToken);
		m.printMapBean(mapBean);
		
		log.info("removeConfig----------------------------");
		String key2 = "testKey02";
		String value2 = "key20121210002";
		client.addConfig(appId, authToken, key2, value2);
		client.addConfig(appId, authToken, key2, "2222");
		client.removeConfig(appId, authToken, key);
		mapBean = client.getConfig(appId, authToken);
		m.printMapBean(mapBean);
		
		log.info("removeConfig----------------------------");
		client.removeConfig(appId, authToken);
		mapBean = client.getConfig(appId, authToken);
		m.printMapBean(mapBean);
		
		log.info("getServiceBaseAddress----------------------------");
		mapBean = client.getServiceBaseAddress();
		m.printMapBean(mapBean);
		
	}
	
	private void printMapBean(Mapbean mapBean) {
		log.info("----------------------------");
		if(mapBean!=null) {
			Map<String, Object> map = mapBean.getMap();
			Set<String> keys = map.keySet();
			for(String key:keys) {
				Object value = (Object) map.get(key);
				log.info(key+":"+value);
			}
		}else{
			log.info("Mapbean为空！");
		}
		log.info("----------------------------");
	}
}
